<template>
<div class="distributor-user views-container">
    <el-dialog width="65%" @close="resetDialogFormData({calc: {all: '0.00',current: '0.00',ing: '0.00',total: '0.00'},data: [],total: 0,pagination: {page: 1,list_rows: 10,pagesizes: [10, 20, 50]}})" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form" v-if="dialogTableVisible">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">分销数据</span>
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <div class="wlm-form-content wlm-table">
                    <el-row type="flex" justify="space-around">
                        <el-col :span="4">
                            <el-card shadow="hover">
                                <div class="text-center">
                                    <p>
                                        <img class="logo" style="margin-right: 5px;" :src="userInfo.avatarUrl">
                                        <span class="ellipsis" style="width: 79px;vertical-align: middle;">{{userInfo.nickName}}</span>
                                        <el-popover placement="top-start" width="200" trigger="hover" content="用户信息">
                                            <el-button size="medium" type="text" slot="reference"><i class="el-icon-question" style="vertical-align: middle;"></i></el-button>
                                        </el-popover>
                                    </p>
                                    <p class="order-gray">ID: {{userInfo.user_id}}</p>
                                </div>
                            </el-card>
                        </el-col>
                        <el-col :span="4">
                            <el-card shadow="hover">
                                <div class="text-center">
                                    <p>
                                        提现中
                                        <el-popover placement="top-start" width="200" trigger="hover" content="提现处理中的佣金">
                                            <el-button size="medium" type="text" slot="reference"><i class="el-icon-question"></i></el-button>
                                        </el-popover>
                                    </p>
                                    <p class="text-danger">￥ {{formFormatData.formData.calc.ing}}</p>
                                </div>
                            </el-card>
                        </el-col>
                        <el-col :span="4">
                            <el-card shadow="hover">
                                <div class="text-center">
                                    <p>可提现
                                        <el-popover placement="top-start" width="200" trigger="hover" content="不包括提现中的金额">
                                            <el-button size="medium" type="text" slot="reference"><i class="el-icon-question"></i></el-button>
                                        </el-popover>
                                    </p>
                                    <p class="text-danger">￥ {{formFormatData.formData.calc.current}}</p>
                                </div>
                            </el-card>
                        </el-col>
                        <el-col :span="4">
                            <el-card shadow="hover">
                                <div class="text-center">
                                    <p>累计提现
                                        <el-popover placement="top-start" width="200" trigger="hover" content="累计提现的佣金">
                                            <el-button size="medium" type="text" slot="reference"><i class="el-icon-question"></i></el-button>
                                        </el-popover>
                                    </p>
                                    <p class="text-danger">￥ {{formFormatData.formData.calc.total}}</p>
                                </div>
                            </el-card>
                        </el-col>
                        <el-col :span="4">
                            <el-card shadow="hover">
                                <div class="text-center">
                                    <p>总佣金
                                        <el-popover placement="top-start" width="200" trigger="hover" content="累计的总佣金">
                                            <el-button size="medium" type="text" slot="reference"><i class="el-icon-question"></i></el-button>
                                        </el-popover>
                                    </p>
                                    <p class="text-danger">￥ {{formFormatData.formData.calc.all}}</p>
                                </div>
                            </el-card>
                        </el-col>
                    </el-row>
                    <el-tabs v-model="formFormatData.api.editForm.params.is_settled" type="card" style="margin-top:10px;" @tab-click="formFormatEditEvt">
                        <el-tab-pane label="普通订单" name="1"></el-tab-pane>
                        <el-tab-pane label="会员订单" name="3"></el-tab-pane>
                    </el-tabs>
                    <div class="wlm-dialog-main wlm-table-content" style="padding:16px 0 0;">
                        <div class="wlm-dialog-content">
                            <el-table :data="formFormatData.formData.data" v-if="formFormatData.api.editForm.params.is_settled=='1'" style="width: 100%">
                                <el-table-column label="订单编号" min-width="68">
                                    <template slot-scope="scope">
                                        {{scope.row.order_no}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="商品/价格">
                                    <template slot-scope="scope">
                                        <div class="wlm-table-logos" v-if="scope.row.order_goods[0]">
                                            <img class="logo" v-if="scope.row.order_goods[0]['image']&&scope.row.order_goods[0]['image']['file_path']" :src="scope.row.order_goods[0]['image']['file_path']">
                                            <div class="inner-text" style="width: 100px;">
                                                <p class="ellipsis" style="width: 120px;">{{scope.row.order_goods[0]['goods_name']}}</p>
                                                <p>￥{{scope.row.order_goods[0]['total_pay_price']}}</p>
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column label="购买人" min-width="55">
                                    <template slot-scope="scope">
                                        <div class="wlm-table-logos">
                                            <img class="logo" :src="scope.row.avatarUrl">
                                            <div class="inner-text ellipsis" style="width: 85px;">
                                                <p class="ellipsis" style="width: 85px;">{{scope.row.nickName}}</p>
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="关系">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.referee">{{scope.row.referee[1]}}</span>
                                        <span v-else>-</span>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="订单状态">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.is_settled!=1">{{scope.row.state_text}}</span>
                                        <span v-if="scope.row.is_settled==1">已完成</span>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="结算状态">
                                    <template slot-scope="scope">
                                        <span>{{scope.row.is_settled==0?'未结算':scope.row.is_settled==1?'已结算':scope.row.is_settled==2?'结算中':''}}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="40" label="入账佣金">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.checked&&scope.row.is_settled!=0">{{scope.row.checked.checkMoney}}</span>
                                        <span v-else>-</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="入账时间" min-width="67">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.settle_time!=0">{{scope.row.settle_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
                                        <span v-if="scope.row.settle_time==0">-</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <!-- 会员 -->
                            <el-table :data="formFormatData.formData.data" v-if="formFormatData.api.editForm.params.is_settled=='3'" style="width: 100%">
                                <el-table-column label="订单编号" min-width="70">
                                    <template slot-scope="scope">
                                        {{scope.row.order_no}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="商品/价格">
                                    <template slot-scope="scope">
                                        <div class="wlm-table-logos">
                                            <div class="inner-text" style="width: 100px;">
                                                <p class="ellipsis" style="width: 120px;">{{scope.row.goods_name}}</p>
                                                <p>￥{{scope.row.pay_price}}</p>
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column label="购买人" min-width="55">
                                    <template slot-scope="scope">
                                        <div class="wlm-table-logos">
                                            <img class="logo" :src="scope.row.avatarUrl">
                                            <div class="inner-text ellipsis" style="width: 85px;">
                                                <p class="ellipsis" style="width: 85px;">{{scope.row.nickName}}</p>
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="关系">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.referee">{{scope.row.referee[1]}}</span>
                                        <span v-else>-</span>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="入账佣金">
                                    <template slot-scope="scope">
                                        {{scope.row.rebate_commission}}
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="订单状态">
                                    <template slot-scope="scope">
                                        <span v-if="scope.row.is_settled!=1">{{scope.row.state_text}}</span>
                                        <span v-if="scope.row.is_settled==1">已完成</span>
                                    </template>
                                </el-table-column>
                                <el-table-column min-width="35" label="结算状态">
                                    <template slot-scope="scope">
                                        <span>{{scope.row.is_settled==0?'未结算':scope.row.is_settled==1?'已结算':scope.row.is_settled==2?'结算中':''}}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="入账时间" min-width="70">
                                    <template slot-scope="scope">
                                        {{scope.row.create_time}}
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                        <div class="pagination-content flex-row flex-justify-b flex-align-c">
                            <el-row class="pagination-btns">
                            </el-row>
                            <el-pagination :disabled="formFormatData.formData.data.length === 0" @current-change="formPageChange" :current-page.sync="formFormatData.formData.pagination.page" :page-sizes="formFormatData.formData.pagination.pagesizes" :page-size.sync="formFormatData.formData.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="formFormatData.formData.data.length > 0 ? formFormatData.formData.total : 0">
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </el-scrollbar>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small" type="primary" @click="dialogTableVisible=false">确定</el-button>
        </footer>
    </el-dialog>
    <el-dialog @close="clearData" :visible.sync="dialogVisibleImg" width="45%" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">{{isAdd?'添加':'编辑'}}分销用户</span>
            </div>
            <div class="wlm-form-content">
                <div class="wlm-dialog-main">
                    <div class="wlm-dialog-content">
                        <el-form ref="user" :model="saveData" size="small" label-width="120px" class="retail-form" label-position="right">
                            <el-form-item label="添加分销商用户" v-if="isAdd">
                                <chooseUser :config="addInitChooseUser" ref="chooseUser" :changeEvt="mainUserChange">
                                </chooseUser>
                                <p class="form-help">请勿随意更改分销商上级，如若出问题自行负责。</p>
                            </el-form-item>
                            <el-form-item label="姓名">
                                <el-input v-model="saveData.real_name" placeholder="请输入姓名" style="width:175px;"></el-input>
                            </el-form-item>
                            <el-form-item label="手机号">
                                <el-input v-model="saveData.mobile" placeholder="请输入手机号" style="width:175px;"></el-input>
                            </el-form-item>
                            <el-form-item :label="isAdd?'上级分销商':'更换分销商上级'">
                                <chooseUser :config="initChooseUser" ref="chooseUser" :changeEvt="userChange">
                                </chooseUser>
                                <p class="form-help">请勿随意更改分销商上级，如若出问题自行负责。</p>
                            </el-form-item>
                            <el-form-item label="更新分销商等级">
                                <el-select v-model="saveData.leave" placeholder="请选择">
                                    <el-option v-for="item in levelData" :key="item.leave" :label="item.leave_title" :value="item.leave">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </div>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small" @click="saveForm" type="primary">保存</el-button>
        </footer>
    </el-dialog>
    <share-link :config="shareLinkConfig" ref="sharelink">
      <template slot="title">-分销</template>
      <template slot="el-form-item">
        <el-form-item label="商品小程序路径" v-if="shareLinkConfig.params.qrUrl">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.qrUrl" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.qrUrl,$event)">复制</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="商品公众号链接" v-if="shareLinkConfig.params.linkUrl">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.linkUrl" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.linkUrl,$event)">复制</el-button>
          </el-input>
        </el-form-item>
        <!-- <el-form-item label="直播商品链接" v-if="shareLinkConfig.params.url">
          <el-input style="width: 270px;" readonly placeholder="请输入内容" v-model="shareLinkConfig.params.url" class="input-with-select">
            <el-button slot="append" @click="handleClipboard(shareLinkConfig.params.url,$event)">复制</el-button>
          </el-input>
        </el-form-item> -->
      </template>
    </share-link>
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <el-button size="small" @click="dialogVisibleImg=true,isAdd=true" type="primary">添加分销商</el-button>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="姓名：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.real_name" placeholder="请输入姓名" style="width:175px;"></el-input>
                    </el-form-item>
                    <el-form-item label="电话：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.mobile" placeholder="请输入电话" style="width:175px;"></el-input>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="用户：" class="search">
                    <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.nickName" placeholder="请输入用户昵称" style="width:175px;"></el-input>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button size="small" type="success" icon="document" :data-query="JSON.stringify(tableFormatData.userTable.files)" v-exceldown="{path:'outputDealerInfo&',query: {type:2}}">导出分销商</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="date" label="用户" :min-width="60">
                    <template slot-scope="scope">
                        <div class="wlm-table-logos flex-row">
                            <img class="logo" :src="scope.row.avatarUrl">
                            <div class="inner-text scale-grow">
                                <router-link class="wlm-text" tag="span" :to="{path:'/user/managementUserEdit', query :{ user_id:scope.row.user_id}}">
                                    <el-button size="mini" type="text" style="display:block;padding-top:2px;">{{scope.row.nickName}}</el-button>
                                </router-link>
                                <el-tooltip class="item" effect="dark" :content="sourceType[`${scope.row.source}`]" placement="top">
                                    <img height="20" width="20" :src="sourceImg[`${scope.row.source || '--'}`]" alt="">
                                </el-tooltip>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="用户资料" :min-width="45">
                    <template slot-scope="scope">
                        <p>{{scope.row.real_name}}</p>
                        <p v-if="scope.row.mobile&&scope.row.mobile!='0'">{{scope.row.mobile}}</p>
                        <p v-else>--</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="分销等级" :min-width="38">
                    <template slot-scope="scope">
                        <span>{{scope.row.leave_title||'--'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="累计佣金/可提现佣金" :min-width="50">
                    <template slot-scope="scope">
                        <p>{{scope.row.total_comm}}</p>
                        <p>{{scope.row.money}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="上级分销商" :min-width="38">
                    <template slot-scope="scope">
                        <p>{{scope.row.referee_name || '--'}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" :label="team_diy=='1'?'下线总数':'客户总数'" :min-width="35" v-if="!is_move_protect">
                    <template slot-scope="scope">
                        <!-- <p>{{scope.row.xx_num}}</p> -->
                        <router-link slot="reference" tag="div" :to="{path:'/distribution/offline', query:{user_id:scope.row.user_id,avatarUrl:scope.row.avatarUrl,nickName:scope.row.nickName,xjfxs_num:scope.row.xjfxs_num,xx_num:scope.row.xx_num}}">
                            <el-button type="text" size="small">{{scope.row.xx_num}}</el-button>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column prop="name" :label="team_diy=='1'?'下线中包含分销商数':'销售总数'" :min-width="42">
                    <template slot-scope="scope">
                        <el-popover trigger="hover" placement="top-start" v-if="team_diy=='1'">
                            <div>
                                <p>一级用户：{{scope.row.first_num}}</p>
                                <p v-if="commission_level==2||commission_level==3">二级用户：{{scope.row.second_num}}</p>
                                <p v-if="commission_level==3">三级用户：{{scope.row.third_num}}</p>
                            </div>
                            <router-link slot="reference" tag="div" :to="{path:'/distribution/offline', query:{user_id:scope.row.user_id,avatarUrl:scope.row.avatarUrl,nickName:scope.row.nickName,xjfxs_num:scope.row.xjfxs_num,xx_num:scope.row.xx_num}}">
                                <el-button type="text" size="small">{{scope.row.xjfxs_num}}</el-button>
                            </router-link>
                        </el-popover>
                        <router-link v-if="team_diy=='2'" tag="div" :to="{path:'/distribution/offline', query:{user_id:scope.row.user_id,avatarUrl:scope.row.avatarUrl,nickName:scope.row.nickName,xjfxs_num:scope.row.xjfxs_num,xx_num:scope.row.xx_num}}">
                            <el-button type="text" size="small">{{scope.row.xjfxs_num}}</el-button>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="成为时间" :min-width="50">
                    <template slot-scope="scope">
                        <span>{{ scope.row.create_time }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" :min-width="100">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <el-button class="wlm-text" type="text" size="small" style="margin-left: 0;" @click="openDialog(scope.row.user_id,scope.row.referee_id,scope.row.leave,scope.row.referee_name,scope.row.real_name,scope.row.mobile)">编辑</el-button>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" size="small" style="margin-left: 0;" @click="sharelink(scope.row.user_id)">推广</el-button>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" size="small" @click="userInfo = { user_id:scope.row.user_id,nickName: scope.row.nickName,avatarUrl: scope.row.avatarUrl }; formFormatDialogEditEvt({id:scope.row.user_id, toggle:'dialogTableVisible'})">佣金</el-button>
                            <div class="btn-line"></div>
                            <router-link class="wlm-text" tag="div" :to="{path:'/distribution/withdrawalApplication', query:{user_id:scope.row.user_id}}">
                                <el-button type="text" size="small">提现</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" size="small" type="text" :data-query="JSON.stringify({dealerID:scope.row.user_id})" v-exceldown="{path:'outputDealerInfo&',query: {type:1}}">导出分销商</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  distributorUser,
  delDistributorUser,
  dealerEdit,
  dealerUserMoney,
  LeaveList,
  dealerAdd,
  distributorExtensionInfo
} from '@/api/distribution'
import mixins from '@/mixins/mixins'
import ChooseUser from '@/components/ChooseUser/index'
import ShareLink from '@/components/ShareLink/index'
import exceldown from '@/directive/exceldown'
import clipboard from '@/utils/clipboard'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'DistributorApplication',
  components: {
    ChooseUser,
    ShareLink
  },
  created() {
    LeaveList().then((response) => {
      const {
        data: {
          data: msgData = []
        }
      } = response
      this.levelData = msgData.data
      this.commission_level = msgData.commission_level
      this.levelData.unshift(msgData.default_leave)
      this.team_diy = msgData.team_diy
      this.is_move_protect = msgData.is_move_protect
      // console.log(this.levelData)
    })
  },
  directives: {
    exceldown
  },
  data() {
    return {
      shareLinkConfig: {
        current: 'weChatQr',
        params: {
          qrUrl: '',
          linkUrl: '',
          weChatQr: '',
          appQr: ''
        }
      },
      team_diy: '',
      commission_level: '',
      is_move_protect: false,
      userInfo: {
        nickName: '',
        user_id: '',
        avatarUrl: ''
      },
      isAdd: false,
      saveData: { user_id: '', referee_id: 0, leave: '', real_name: '', mobile: '', change: 0 },
      levelData: [],
      dialogVisibleImg: false,
      dialogTableVisible: false,
      initChooseUser: {
        closable: true,
        initList: [],
        requestApi: distributorUser
      },
      addInitChooseUser: {
        closable: true,
        initList: []
      },
      formFormatData: {
        key: 'formFormat',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            api: dealerUserMoney,
            params: {
              page: 1,
              is_settled: '1'
            },
            redirect: 'user_id'
          }
        },
        formData: {
          calc: {
            all: '0.00',
            current: '0.00',
            ing: '0.00',
            total: '0.00'
          },
          data: [],
          total: 0,
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50]
          }
        },
        rules: {}
      },
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: distributorUser,
            delList: delDistributorUser,
            msgConfig: {
              del: {
                type: 'warning',
                msg: '此操作会删除用户的所有数据，名下所有平台内如有正在交易的订单、金额，删除后所产生的纠纷由服务商自身承担 如要删除请慎重操作！！'
              }
            }
          },
          tableData: [],
          files: {
            ids: [],
            checkall: '0',
            Recycle: '1',
            redirect: 'user_id'
          },
          change: {
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  mounted() {

  },
  methods: {
    handleClipboard(text, event) {
      clipboard(text, event)
    },
    sharelink(user_id) {
      distributorExtensionInfo({ user_id }).then(res => {
        const { data: { data: { weChat_qrcode, wxApp_qrcode, weChat_url, wxApp_url } } } = res
        this.shareLinkConfig.params.qrUrl = wxApp_url
        this.shareLinkConfig.params.linkUrl = weChat_url
        this.shareLinkConfig.params.weChatQr = weChat_qrcode
        this.shareLinkConfig.params.appQr = wxApp_qrcode
        this.shareLinkConfig.current = weChat_qrcode ? 'weChatQr' : weChat_qrcode ? 'appQr' : ''
      })
      this.$refs.sharelink.toggle()
    },
    formPageChange(page) {
      this.formFormatData.api.editForm.params.page = page
      this.formFormatEditEvt(true)
    },
    openDialog(user_id, referee_id, leave, referee_name, real_name, mobile) {
      this.isAdd = false
      if (referee_id !== 0 && referee_name) {
        this.initChooseUser.initList = [{ user_id: referee_id, nickName: referee_name }]
      } else {
        this.initChooseUser.initList = []
      }
      this.saveData.user_id = user_id
      this.saveData.referee_id = referee_id
      this.saveData.real_name = real_name
      this.saveData.mobile = mobile
      this.saveData.leave = leave
      this.dialogVisibleImg = true
    },
    clearData() {
      console.log('clear')
      this.saveData = { user_id: '', referee_id: 0, leave: '', mobile: '', real_name: '', change: 0 }
      this.$refs.chooseUser.clearData()
      this.$refs.chooseUser.filesEmpty()
    },
    // 打开了关闭要清掉id
    saveForm() {
      console.log(this.saveData.referee_id)
      if (/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.saveData.mobile)) {
        if (this.isAdd) {
          dealerAdd({ user_id: this.saveData.user_id, referee_id: this.saveData.referee_id, real_name: this.saveData.real_name, mobile: this.saveData.mobile, leave: this.saveData.leave }).then((response) => {
            const { data: { code, data, msg } } = response
            console.log(data)
            if (code === 1) {
              this.$message({
                type: 'success',
                message: '修改成功!'
              })
              this.dialogVisibleImg = false
              this.filesSerch()
            } else {
              this.dialogVisibleImg = false
              this.$message.error(msg)
            }
          })
        } else {
          dealerEdit({ user_id: this.saveData.user_id, referee_id: this.saveData.referee_id, real_name: this.saveData.real_name, mobile: this.saveData.mobile, leave: this.saveData.leave, change: this.saveData.change }).then((response) => {
            const { data: { code, data, msg } } = response
            console.log(data)
            if (code === 1) {
              this.$message({
                type: 'success',
                message: '修改成功!'
              })
              this.dialogVisibleImg = false
              this.filesSerch()
            } else {
              this.dialogVisibleImg = false
              this.$message.error(msg)
            }
          })
        }
      } else {
        this.$message.error('手机号格式错误')
      }
    },
    userChange(userlist) {
      const [item] = userlist
      this.saveData.change = 1
      if (item) {
        this.saveData.referee_id = item.user_id
      } else {
        this.saveData.referee_id = 0
      }
    },
    mainUserChange(userlist) {
      const [item] = userlist
      if (item) {
        this.saveData.user_id = item.user_id
      } else {
        this.saveData.user_id = 0
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.distributor-user {
    /deep/ .el-card__body {
        padding: 10px;
    }
}
</style>
